package com.example.knife4j.demo.controller;

import com.example.knife4j.demo.param.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(tags = "01-示例模板",value = "备注")
@RestController
@RequestMapping("example")
public class Example01Controller {

    @ApiOperation(value = "01-hello接口",notes = "备注")
    @GetMapping("hello")
    public String hello(){
        return "Hello World";
    }

    @ApiOperation("02-hi接口")
    @GetMapping("hi")
    public String hi(@RequestParam("name") String name){
        return name+"hi！ Hello World！";
    }

    @ApiOperation("02-hiAndAge接口")
    @GetMapping("hiAndAge")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名", required = true,example = "张三"),
            @ApiImplicitParam(name = "age", value = "用户年龄", required = true,example = "20")
    })
    public String hiAndAge(@RequestParam("name") String name,@RequestParam("age") Integer age){
        return name+"hi！ Hello World！and age="+age;
    }

    @ApiOperation("03-name接口")
    @GetMapping("user/{name}")
    @ApiImplicitParam(name = "name", value = "用户名", required = true,example = "张三")
    public String name(@PathVariable String name){
        return name+" Hello World";
    }
    @ApiOperation("03-nameAndId接口")
    @GetMapping("user/id/{name}/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名", required = true,example = "张三"),
            @ApiImplicitParam(name = "id", value = "用户id", required = true,example = "200")
    })
    public String nameAndId(@PathVariable String name,@PathVariable String id){
        return name+" Hello World and id="+id;
    }

    @ApiOperation("03-info接口")
    @PostMapping("info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "用户名", required = true,example = "张三"),
            @ApiImplicitParam(name = "id", value = "用户id", required = true,example = "200")
    })
    public String info(@RequestBody User user){
        return "Hello World===="+user.toString();
    }

}
